package com.smyx.controller;

import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;

/**
 * Kafka生产者
 * @author SmyxCoding
 * @date 2022/08/17/17:13
 */
@RestController
public class KafkaController {
    private final KafkaTemplate<String, Object> kafkaTemplate;
    public KafkaController(KafkaTemplate<String, Object> kafkaTemplate) {
        this.kafkaTemplate = kafkaTemplate;
    }

    @RequestMapping("/kafka/send")
    public void send() {
        kafkaTemplate.send("testTopic",  "测试kafka消息>>> " + LocalDateTime.now());
    }
}
